<template>
    <view>
       <News :newsList="newsList"/>
       <u-loadmore :status="status" />
    </view>
</template>
<script> 
import News from './components/Newss.vue'
	import {
		getNoticeList
	} from '@/api/index'
import {
    mapState,
  
} from 'vuex'
export default {
    components:{
        News
    },
    data(){
        return {
            newsList:[],
            query:{
                pageNum:1,
                pageSize:10
            },
            total:0,
            status:'loading'

        }
    },
    computed:{
        ...mapState("community",["communityId"]),
    },
   onLoad(){
        this.init()
    },
    onReachBottom(){

        if(this.newsList.length<this.total){
            this.status='loading'
            this.query.pageNum++
            this.init()
        }else{
            this.status='nomore'
        }
    },
    methods:{
        async init(){
       
            let datas=await getNoticeList({
                pageNum:this.query.pageNum,
                pageSize:this.query.pageSize,
                communityId:this.communityId
            })
            this.newsList=[...this.newsList,...datas.rows]
            this.total=datas.total
       
            if(this.newsList.length>=this.total){
                this.status='nomore'
            }else{
              this.status='loading'
            }
        }
    },
   
}   
</script>